﻿<%@ Page Title="" Language="C#" MasterPageFile="~/_Default.Master" AutoEventWireup="true" CodeBehind="Projects.aspx.cs" Inherits="WebApplication.Projects" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <%--标签--%>
    <div class="search-card">
    </div>

    <%--内容--%>
    <div class="layui-row layui-col-space10 mt-20 mb-10">

            <% if (projects.Count > 0)
                { %>
            <% foreach (Models.Projects project in projects)
                { %>

            <div class="layui-col-md6">
                <div class="project-item" url="/Project/Detail.aspx?id=<%=project.ProjectID %>">
                    <div class="info flex-grow-1">
                        <div class="flex-container">
                            <div class="flex-grow-1 title text-ellipsis">
                                <%=project.Title %>
                            </div>
                            <div class="flex-shrink-0  price">
                                ¥ <%=project.PriceMin %> ~ <%=project.PriceMax %>
                            </div>
                        </div>
                        <div class="created">
                            <span class="nickname text-ellipsis"><%=project.Owner.NickName %></span>
                            发布于<%=project.CreatedAt %>
                        </div>
                        <div class="tag">
                            <% if (project.Identity == 1)
                                {%>
                            <span class="el-tag el-tag--mini el-tag--light">私人</span>
                            <%} %>
                            <% if (project.Identity == 2)
                                {%>
                            <span class="el-tag el-tag--mini el-tag--light">社团/店铺</span>
                            <%} %>
                            <% if (project.Identity == 3)
                                {%>
                            <span class="el-tag el-tag--mini el-tag--light">公司企业</span>
                            <%} %>

                            <%
                                List<string> tags = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(project.Tag);
                                tags.Remove("@");
                                foreach (string tag in tags)
                                {
                            %>
                            <span class="el-tag el-tag--info el-tag--mini el-tag--light"><%=tag %></span>
                            <%} %>
                        </div>
                        <div class="info2">
                            <div class="label-wrapper">
                                <span class="label">截稿日期：</span>
                                <span class="value"><%=project.Deadline.ToString("yyyy-MM-dd") %></span>
                            </div>
                            <div class="label-wrapper">
                                <span class="label">应征人数：</span>
                                <span class="value"><%=project.ApplyCount %></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <%} %>

            <script>
                $('.project-item').on('click', e => {
                    let url = $(e.delegateTarget).attr("url");
                    if (url) {
                        location.href = url;
                    }
                })
            </script>
            <%}
                else
                { %>

            <div class="empty"></div>

            <%} %>

        </div>

    <%--分页--%>
    <div class="text-center" id="laypage"></div>


    <script>
        const data = [
            {
                name: '类型',
                value: 'type',
                children: [
                    {
                        name: '全部',
                        value: ''
                    },
                ].concat(tagOptions.types.map(item => { return { name: item, value: item } }))
            },
            {
                name: '风格',
                value: 'style',
                children: [
                    {
                        name: '全部',
                        value: ''
                    }
                ].concat(tagOptions.styles.map(item => { return { name: item, value: item } }))
            }
        ]


        utils.searchTags({
            data,
            elem: '.search-card',
            click: (opt) => {
                let url = new URL(location.href);
                url.searchParams.set(opt.name, opt.value);
                location.href = url;
            }
        })

        layui.use('laypage', function () {
            var laypage = layui.laypage;

            //执行一个laypage实例
            laypage.render({
                elem: 'laypage' //注意，这里的 test1 是 ID，不用加 # 号
                , count: <%=totalCount%> //数据总数，从服务端得到
              , curr:<%=pageIndex%>
              , limit:<%=pageSize%>
              , jump: function (obj, first) {
                    //obj包含了当前分页的所有参数，比如：
                    //console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                    //console.log(obj.limit); //得到每页显示的条数

                    //首次不执行
                    if (!first) {
                        let url = new URL(location.href);
                        url.searchParams.set("pageIndex", obj.curr)
                        location.href = url;
                    }
                }
            });
        });
    </script>
</asp:Content>
